package com.wyy.controller;

import com.wyy.beans.User;
import com.wyy.common.Result;
import com.wyy.service.UserService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/user")
    @RequiresRoles(value = {"admin","driver"} ,logical = Logical.OR)
    public Result<User> addUser(@RequestBody User user){
        return userService.addUser(user);
    }

    @DeleteMapping("/user/{uid}")
    @RequiresRoles("admin")
    public Result<User> deleteUser(@PathVariable long uid){
        return userService.deleteUser(uid);
    }

    @PutMapping("/updateUser")
    @RequiresRoles("admin")
    public Result<User> updateUser(@RequestBody User user) {
        return userService.updateUser(user);
    }

    @GetMapping("/user/{telephoneNumber}")
    public Result<User> getUserByTelephoneNumber(@PathVariable String telephoneNumber) {
        return userService.getUserByTelephoneNumber(telephoneNumber);
    }
}
